package main.listeners;

import java.awt.Graphics;

import main.bots.Bot;
import main.bots.Methods;



public class PaintHandler {
	
	public static PaintListener toPaint = null;
	public static boolean paint = true;
	
	@SuppressWarnings("static-access")
	public static void callRepaint(Graphics g) {
		//Methods.getClientToUse().useThese().paint(g);
		if(!paint)
			return;
		Bot b = null;
		b = Methods.getClientToUse().scriptMan.botRunning;
		if(b == null)
			return;
		if(toPaint == null) {
			Class<?>[] temp = b.getClass().getInterfaces();
			for(int i = 0; i < temp.length; i++) {
				if(temp[i] == null)
					continue; //Possible?
				String s = temp[i].getName();
				System.out.println(b.getClass().getName() + " implements Interface: " + s);
				if(s.toLowerCase().trim().contains("paintlistener")) {
					toPaint = (PaintListener) b;
					break;
				}
			}
			
			if(toPaint == null) {
				System.out.println("This class is not using paint, never painting again");
				paint = false;
				return;
			}
		PaintListener a = (PaintListener) Methods.getClientToUse().scriptMan.botRunning;
		if(a != null) {
		
			Methods.getCanvas().repaint();
			paint = true;
		}
		} else {
			Methods.getCanvas().repaint();
			paint = true;
		}
		
	}

}
